// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ORDER_OML_O39 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("25 ORC",25)]
  	    [HL7Field(HL7Version.v27, 25, HL7Repeat.False, HL7Required.True,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("26 PRT",26)]
  	    [HL7Field(HL7Version.v27, 26, HL7Repeat.True, HL7Required.False,"PRT")]
	    public PRT[] PRT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("27 TIMING",27)]
  	    [HL7Field(HL7Version.v27, 27, HL7Repeat.True, HL7Required.False,"TIMING_OML_O39")]
	    public TIMING_OML_O39[] TIMING {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("31 OBSERVATION_REQUEST",31)]
  	    [HL7Field(HL7Version.v27, 31, HL7Repeat.False, HL7Required.False,"OBSERVATION_REQUEST_OML_O39")]
	    public OBSERVATION_REQUEST_OML_O39 OBSERVATION_REQUEST {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("69 FT1",69)]
  	    [HL7Field(HL7Version.v27, 69, HL7Repeat.True, HL7Required.False,"FT1")]
	    public FT1[] FT1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("70 CTI",70)]
  	    [HL7Field(HL7Version.v27, 70, HL7Repeat.True, HL7Required.False,"CTI")]
	    public CTI[] CTI {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("71 BLG",71)]
  	    [HL7Field(HL7Version.v27, 71, HL7Repeat.False, HL7Required.False,"BLG")]
	    public BLG BLG {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			PRT = PopSegmentParseAndCheckRequiredArray<PRT>(availableData, options, "PRT");
			TIMING = ProcessGroupArray<TIMING_OML_O39>(availableData, options, "TIMING");
			OBSERVATION_REQUEST = ProcessGroup<OBSERVATION_REQUEST_OML_O39>(availableData, options, "OBSERVATION_REQUEST");
			FT1 = PopSegmentParseAndCheckRequiredArray<FT1>(availableData, options, "FT1");
			CTI = PopSegmentParseAndCheckRequiredArray<CTI>(availableData, options, "CTI");
			BLG = PopSegmentParseAndCheckRequired<BLG>(availableData, options, "BLG");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			bool isPRT = availableData.StartsWith("PRT", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PRT", options.Version) || isPRT) {
				return isPRT;
			}
			TIMING_OML_O39 testTIMING_OML_O39 = new TIMING_OML_O39();
			bool grpCCTIMING_OML_O39 = (testTIMING_OML_O39.CanConsume(availableData, options));
			if (IsRequired("TIMING", options.Version) || grpCCTIMING_OML_O39) {
				return grpCCTIMING_OML_O39;
			}
			OBSERVATION_REQUEST_OML_O39 testOBSERVATION_REQUEST_OML_O39 = new OBSERVATION_REQUEST_OML_O39();
			bool grpCCOBSERVATION_REQUEST_OML_O39 = (testOBSERVATION_REQUEST_OML_O39.CanConsume(availableData, options));
			if (IsRequired("OBSERVATION_REQUEST", options.Version) || grpCCOBSERVATION_REQUEST_OML_O39) {
				return grpCCOBSERVATION_REQUEST_OML_O39;
			}
			bool isFT1 = availableData.StartsWith("FT1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("FT1", options.Version) || isFT1) {
				return isFT1;
			}
			bool isCTI = availableData.StartsWith("CTI", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CTI", options.Version) || isCTI) {
				return isCTI;
			}
			bool isBLG = availableData.StartsWith("BLG", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("BLG", options.Version) || isBLG) {
				return isBLG;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ORDER";
			}
        }

        static ORDER_OML_O39() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ORDER_OML_O39));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PRT != null && PRT.Length > 0) {
			for (int i = 0; i < PRT.Length; i++) {
				string segmentValue = PRT[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (TIMING != null && TIMING.Length > 0) {
			for (int i = 0; i < TIMING.Length; i++) {
				string segmentValue = TIMING[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBSERVATION_REQUEST != null) {
			string segmentValue = OBSERVATION_REQUEST.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (FT1 != null && FT1.Length > 0) {
			for (int i = 0; i < FT1.Length; i++) {
				string segmentValue = FT1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (CTI != null && CTI.Length > 0) {
			for (int i = 0; i < CTI.Length; i++) {
				string segmentValue = CTI[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (BLG != null) {
			string segmentValue = BLG.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

